package com.sunda.spmswms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunda.spmswms.entity.SapPackageBox;
import com.sunda.spmswms.mapper.SapPackageBoxMapper;
import com.sunda.spmswms.service.ISapPackageBoxService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 装箱单箱码关系表 服务实现类
 * </p>
 *
 * @author Wayne
 * @since 2021-04-22
 */
@Service
public class SapPackageBoxServiceImpl extends ServiceImpl<SapPackageBoxMapper, SapPackageBox> implements ISapPackageBoxService {

    /** 出库任务结果明细，更新装箱单箱码实际出库箱码数量。存在一个箱码对多行数据，可能一次更新多行数据。 */
    @Override
    public int updateSapPackageBox(String packageList, String boxNote, double actualOperateQty, String whsOutUuid, String containerBrand, String packingSpec, String loadingType) {
        SapPackageBox sapPackageBox = new SapPackageBox();
        sapPackageBox.setActualOperateQty(actualOperateQty);
        sapPackageBox.setWhsOutUuid(whsOutUuid);
        sapPackageBox.setContainerBrand(containerBrand);
        sapPackageBox.setPackingSpec(packingSpec);
        sapPackageBox.setLoadingType(loadingType);
        return this.baseMapper.update(sapPackageBox, new QueryWrapper<SapPackageBox>()
                .eq("PACKAGE_LIST", packageList).eq("BOX_NOTE", boxNote));
    }

    /** 多出的箱码，新增数据到装箱单箱码关系表中，unplanned = 1 表示是计划之外新增出库的箱码 */
    @Override
    public int addSapPackageBox(String packageList, String boxNote, double actualOperateQty, String unplanned, String whsOutUuid, String containerBrand, String packingSpec, String loadingType) {
        SapPackageBox sapPackageBox = new SapPackageBox();
        sapPackageBox.setPackageList(packageList);
        sapPackageBox.setBoxNote(boxNote);
        sapPackageBox.setActualOperateQty(actualOperateQty);
        sapPackageBox.setUnplanned(unplanned);
        sapPackageBox.setWhsOutUuid(whsOutUuid);
        sapPackageBox.setContainerBrand(containerBrand);
        sapPackageBox.setPackingSpec(packingSpec);
        sapPackageBox.setLoadingType(loadingType);
        return this.baseMapper.insert(sapPackageBox);
    }

    @Override
    public int deleteUnplannedBN(String whsOutUuid, String unplanned) {
        QueryWrapper<SapPackageBox> queryWrapper = new QueryWrapper<SapPackageBox>()
                .eq("WHS_OUT_UUID", whsOutUuid).eq("UNPLANNED", unplanned);
        return this.baseMapper.delete(queryWrapper);
    }
}
